package chapter17;

/**
 * @author yt1105
 * @version 1.0
 * main 方法里面实现两个子线程
 */
public class Thread03 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        T2 t2 = new T2();
        Thread thread1 = new Thread(t1);
        Thread thread2 = new Thread(t2);
        thread1.start();//启动第一个线程
        thread2.start();//启动第二个线程
        //我们在这里就实现了两个线程在里面

    }
    //编写一个程序，让我们实现
}

@SuppressWarnings("all")
class T1 implements Runnable {
    int count = 0;

    @Override
    public void run() {
        //每隔1秒钟 输出HelloWorld输出10次
        while (true) {
            System.out.println("hello world" + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

@SuppressWarnings("all")
class T2 implements Runnable {
    int count = 0;

    @Override
    public void run() {
        //我们在这里去写我们的业务代码 每个线程去完成自己的任务
        while (true) {
            System.out.println("hi hi" + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
